package com.valveinspectionsys.repair.db;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;

import com.valveinspectionsys.base.BaseDao;
import com.valveinspectionsys.dbhelp.DbTableName;
import com.valveinspectionsys.httpserver.DownloadItem;
import com.valveinspectionsys.httpserver.RequestUrl;
import com.valveinspectionsys.httpserver.UpdateVo;
import com.valveinspectionsys.httpserver.UploadItem;
import com.valveinspectionsys.httpserver.UploadPOVO;
import com.valveinspectionsys.povo.DeviceItem;
import com.valveinspectionsys.povo.DeviceSubItem;
import com.valveinspectionsys.povo.DeviceVo;
import com.valveinspectionsys.povo.RepairVo;
import com.valveinspectionsys.povo.SpinnerVo;
import com.valveinspectionsys.util.DateUtil;
import com.valveinspectionsys.util.FileNameUtil;
import com.valveinspectionsys.util.Model;

/**
 * 维修数据交互
 * @author King
 *
 */
public class RepairDao extends BaseDao{
    
    private SQLiteDatabase  db;
      
    public SQLiteDatabase getDb() {
        return db;
    }

    public void setDb(SQLiteDatabase db) {
        this.db = db;
    }

    public RepairDao(Context context, String SqliteName) {
  	super(context, SqliteName);
  	this.db=super.getDb();
      }
    
    /**
     * 查询当前设备册的巡检或保养数据
     * @param devicelistid  设备册ID
     * @param devicetype   类型（0,1巡检，2保养,3维修）
     * @return  Object 巡检项目信息
     */
    public List<DeviceItem> queryDeviceItem(String devicelistid,String devicetype){
	
	String sql="select * from devicelist where number='"+devicelistid+"'";
	Cursor cursor=db.rawQuery(sql, null);
	String str="";
	List<DeviceItem> list=new ArrayList<DeviceItem>();
	String[] s=null;
	if(cursor.moveToNext()){
	    str=cursor.getString(cursor.getColumnIndex("deviceitem"));
	    if(str.indexOf(",")>0){
		 s=str.split(",");
	    }
	}
	if(cursor!=null){
	    cursor.close();
	}
	sql="select di.[_id] as itemid, di.[name] as itemname,di.[number] as itemnumber,di.[type],di.[forcedpictures]" +
			",dsi.[name] as subname,dsi.[number] as subnumber,dsi.[itemNumber],dsi.[_id] as subid" +
			" from deviceItem di,devicesubitem dsi where di.[number]=dsi.[itemNumber] and di.[type]='"+devicetype+"' " +
			" and di.[number] in (";
	for(int i=0;i<s.length;i++){
	    sql=sql+s[i]+",";
	}	
	sql=sql.substring(0, sql.length()-1);	
	sql=sql+") order by di.number";	
	cursor=db.rawQuery(sql, null);
	  DeviceItem item=null;
	    List<DeviceSubItem> subitem=null;
	while(cursor.moveToNext()){	  
	    String itemid=cursor.getString(cursor.getColumnIndex("itemid"));
	    if(list.size()==0||!list.get(list.size()-1).getDeviceItemID().equals(itemid)){		
		item=new DeviceItem();
		subitem=new ArrayList<DeviceSubItem>();
		item.setDeviceItemID(itemid);
		item.setDeviceItemName(cursor.getString(cursor.getColumnIndex("itemname")));
		item.setDeviceItemNumber(cursor.getString(cursor.getColumnIndex("itemnumber")));
		item.setDeviceItemType(cursor.getString(cursor.getColumnIndex("type")));
		item.setForcedpictures(cursor.getString(cursor.getColumnIndex("forcedpictures")));
		list.add(item);
	    }	   
	   DeviceSubItem suitem=new DeviceSubItem();
	    suitem.setDeviceItemNumbeer(cursor.getString(cursor.getColumnIndex("itemNumber")));
	    suitem.setId(cursor.getString(cursor.getColumnIndex("subid")));	 
	    suitem.setName(cursor.getString(cursor.getColumnIndex("subname")));
	    suitem.setNumber(cursor.getString(cursor.getColumnIndex("subnumber")));
	    subitem.add(suitem);
	    item.setSubitem(subitem);
	}
	if(cursor!=null){
	    cursor.close();
	}
	return list;
	
    }
    
    /**
     * 查询设备信息（分页）
     * @param model
     * @param deviceListid
     * @param devicenumber
     * @param devicename
     * @param copystatus
     * @return
     */
     public List<DeviceVo> queryModelDevice(Model model,String deviceadds,String devicenumber,
	     String devicetype,String copystatus,String devicelistid){
	 
	 StringBuffer sb=new StringBuffer("select * from deviceinfo where   operationtype='3'");
	 if(deviceadds!=null&&!TextUtils.isEmpty(deviceadds)){
	     sb.append(" and deviceadds like'%").append(deviceadds).append("%'");
	 }
	 if(devicetype!=null&&!TextUtils.isEmpty(devicetype)&&!devicetype.equals("请选择")){
	     sb.append(" and devicetype ='").append(devicetype).append("'");
	 }
	 if(devicenumber!=null&&!TextUtils.isEmpty(devicenumber)){
	     sb.append(" and devicenumber='").append(devicenumber).append("'");
	 }
	 if(copystatus!=null&&!TextUtils.isEmpty(copystatus)&&!copystatus.equals("请选择")){
	     sb.append(" and iscopystatus = '").append(copystatus).append("'");
	 }
	 if(devicelistid!=null&&!TextUtils.isEmpty(devicelistid)&&!devicelistid.equals("0")){
	     sb.append("  and devicelistid='").append(devicelistid).append("'");
	 }
	 sb.append("order by devicelistid,iscopystatus");
	 String sql=sb.toString();
	 List<DeviceVo> list=new ArrayList<DeviceVo>();
	 Cursor cursor=super.getAllItems( (model.getIndex() - 1) * model.getView_Count(), model.getView_Count(), sql);
	 while(cursor.moveToNext()){
	     DeviceVo device=new DeviceVo();
	     device.setId(cursor.getString(cursor.getColumnIndex("_id")));
	     device.setDeviceId(cursor.getString(cursor.getColumnIndex("deviceid")));
	  
	     device.setDeviceNumber(cursor.getString(cursor.getColumnIndex("devicenumber")));
	     device.setDeviceAdds(cursor.getString(cursor.getColumnIndex("deviceadds")));
	    
	     device.setDeviceCaliber(cursor.getString(cursor.getColumnIndex("devicecaliber")));
	     device.setDeviceType(cursor.getString(cursor.getColumnIndex("devicetype")));
	     device.setDevicePressure(cursor.getString(cursor.getColumnIndex("devicePressure")));
	     device.setInspectionCycle(cursor.getString(cursor.getColumnIndex("inspectionCycle")));
	     device.setInstallationDate(cursor.getString(cursor.getColumnIndex("InstallationDate")));
	     device.setLongitude(cursor.getDouble(cursor.getColumnIndex("longitude")));
	     device.setLatitude(cursor.getDouble(cursor.getColumnIndex("latitude")));
	     device.setMaintenanceCycle(cursor.getString(cursor.getColumnIndex("maintenanceCycle")));
	     device.setProducers(cursor.getString(cursor.getColumnIndex("producers")));
	     device.setProductionDate(cursor.getString(cursor.getColumnIndex("productionDate")));
	     device.setRfidNumber(cursor.getString(cursor.getColumnIndex("RFIDnumber")));
	     device.setCopystatus(cursor.getString(cursor.getColumnIndex("iscopystatus")).equals("1")?"已维修":"未维修");
	     device.setOpenStatus(cursor.getString(cursor.getColumnIndex("openStatus")));
	     device.setUseStatus(cursor.getString(cursor.getColumnIndex("useStatus")));
	     list.add(device);	     
	 }
	 if(cursor!=null){
	     cursor.close();
	 }
	return list;
	 
     }
     
     /**
      * 查询总页数
      * @param deviceListid
      * @param devicenumber
      * @param devicename
      * @param copystatus
      * @return
      */
     public int queryPageCount (String deviceadds,String devicenumber,
	     String devicetype,String copystatus,String devicelistid){
	 int page=0;
	 
	 StringBuffer sb=new StringBuffer("select * from deviceinfo   where  operationtype='3'");
	 if(deviceadds!=null&&!TextUtils.isEmpty(deviceadds)){
	     sb.append(" and deviceadds like'%").append(deviceadds).append("%'");
	 }
	 if(devicetype!=null&&!TextUtils.isEmpty(devicetype)&&!devicetype.equals("请选择")){
	     sb.append(" and devicetype ='").append(devicetype).append("'");
	 }
	 if(devicenumber!=null&&!TextUtils.isEmpty(devicenumber)){
	     sb.append(" and devicenumber='").append(devicenumber).append("'");
	 }
	 if(copystatus!=null&&!TextUtils.isEmpty(copystatus)&&!copystatus.equals("请选择")){
	     sb.append(" and iscopystatus = '").append(copystatus).append("'");
	 }
	 if(devicelistid!=null&&!TextUtils.isEmpty(devicelistid)&&!devicelistid.equals("0")){
	     sb.append("  and devicelistid='").append(devicelistid).append("'");
	 }
	 String sql=sb.toString();
	 int k=getCount(sql);
	 page=k % 10 > 0 ? k / 10 + 1 : k / 10;
	return page;
     }
     
     
     /**
      * 查询设备总数
      * @return
      */
     public int queryAllDeviceTotal(String devicelistid){
	 int k=0;
	 String sql="select count(_id) as total from deviceinfo  where operationtype='3'";
	 if(devicelistid!=null){
	     sql=sql+" and devicelistid='"+devicelistid+"'";
	 }
	 Cursor cursor=db.rawQuery(sql, null);
	 if(cursor.moveToNext()){
	     k=cursor.getInt(cursor.getColumnIndex("total"));
	 }
	 if(cursor!=null){
	     cursor.close();
	 }
	 
	return k;
     }
     
     /**
      * 查询所有设备未抄数
      * @return
      */
     public int queryNoCopyDeviceTotal(String devicelistid){
	 int k=0;
	 String sql="select count(_id) as total from repairSingle  where repairtype='1' and repairstatus='0' ";
	 if(devicelistid!=null){
	     sql=sql+" and devicelistid='"+devicelistid+"'";
	 }
	 Cursor cursor=db.rawQuery(sql, null);
	 if(cursor.moveToNext()){
	     k=cursor.getInt(cursor.getColumnIndex("total"));
	 }
	 if(cursor!=null){
	     cursor.close();
	 }
	return k;
     }
     
     /**
      * 查询未上传数
      * @return
      */
     public int queryNoUploadDeviceTotal(){
	 int k=0;
	 String sql="select count(_id) as total from repairSingle  where repairtype='1' and repairstatus='1' and isupload='0'";
	
	 Cursor cursor=db.rawQuery(sql, null);
	 if(cursor.moveToNext()){
	     k=cursor.getInt(cursor.getColumnIndex("total"));
	 }
	 if(cursor!=null){
	     cursor.close();
	 }
	return k;
     }
     
     /**
      * 查询所有已维修数
      * @return
      */
    public int queryCopyData(){
	 int k=0;
	 String sql="select count(_id) as total from repairSingle  where repairtype='1' and repairstatus='1' ";
	
	 Cursor cursor=db.rawQuery(sql, null);
	 if(cursor.moveToNext()){
	     k=cursor.getInt(cursor.getColumnIndex("total"));
	 }
	 if(cursor!=null){
	     cursor.close();
	 }
	return k;
    }
     
     /**
      * 通过RFID 编号 或ID查询一个巡检设备信息
      * @param rfidNumber
      * @param deviceid
      * @return
      */
     public DeviceVo queryRfidDevice(String rfidNumber,String deviceid,boolean b){
	 
	 String sql="select * from deviceinfo di,devicelist dl where  di.[devicelistid]=dl.[devicelistid] and di.[operationtype]='3'and dl.[operationtype]='3'";
	 if(rfidNumber!=null){
	     sql=sql+" and rfidNumber='"+rfidNumber+"'";
	 }
	 if(deviceid!=null){
	     sql=sql+" and deviceid='"+deviceid+"'";
	 }
	 Cursor cursor=db.rawQuery(sql, null);
	 DeviceVo device=null;
	 if(cursor.moveToNext()){
	     device=new DeviceVo();
	     device.setId(cursor.getString(cursor.getColumnIndex("_id")));
	     device.setDeviceId(cursor.getString(cursor.getColumnIndex("deviceid")));
	     device.setUseStatus(cursor.getString(cursor.getColumnIndex("useStatus")));
	     device.setOpenStatus(cursor.getString(cursor.getColumnIndex("openStatus")));
	     device.setDeviceNumber(cursor.getString(cursor.getColumnIndex("devicenumber")));
	     device.setDeviceAdds(cursor.getString(cursor.getColumnIndex("deviceadds")));
	     device.setDeviceCaliber(cursor.getString(cursor.getColumnIndex("devicecaliber")));
	     device.setDeviceType(cursor.getString(cursor.getColumnIndex("devicetype")));
	     device.setDevicePressure(cursor.getString(cursor.getColumnIndex("devicePressure")));
	     device.setInspectionCycle(cursor.getString(cursor.getColumnIndex("inspectionCycle")));
	     device.setInstallationDate(cursor.getString(cursor.getColumnIndex("InstallationDate")));
	     device.setLongitude(cursor.getDouble(cursor.getColumnIndex("longitude")));
	     device.setLatitude(cursor.getDouble(cursor.getColumnIndex("latitude")));
	     device.setMaintenanceCycle(cursor.getString(cursor.getColumnIndex("maintenanceCycle")));
	     device.setProducers(cursor.getString(cursor.getColumnIndex("producers")));
	     device.setProductionDate(cursor.getString(cursor.getColumnIndex("productionDate")));
	     device.setRfidNumber(cursor.getString(cursor.getColumnIndex("RFIDnumber")));
	     device.setCopystatus(cursor.getString(cursor.getColumnIndex("iscopystatus")));
	     device.setCopydata(cursor.getString(cursor.getColumnIndex("copydata")));
	    
	     device.setCopydate(cursor.getString(cursor.getColumnIndex("copydate")));
             device.setDeviceListId(cursor.getString(cursor.getColumnIndex("devicelistid")));
             device.setDeviceListdeviceitem(cursor.getString(cursor.getColumnIndex("deviceitem")));
             device.setRemark(cursor.getString(cursor.getColumnIndex("remark")));
             device.setCopystatus(cursor.getString(cursor.getColumnIndex("iscopystatus")).equals("1")?"已维修":"未维修");
             
	 }
	
	 if(cursor!=null){
	     cursor.close();
	 }
	return device;
	 
     }
     
     /**
      * 删除重复设备册
      * @param devicelistid
      * @return
      */
     public boolean delectDuplicateList(String devicelistid){
	    
	        db.delete(DbTableName.DEVICEINFO,"devicelistid='"+devicelistid+"'", null);
	        db.delete(DbTableName.DEVICELIST, "devicelistid='"+devicelistid+"'", null);
	        db.delete(DbTableName.RESOURCES, "devicelistid='"+devicelistid+"'", null);
	        db.delete(DbTableName.NAVIGATION, "waterlistid='"+devicelistid+"'",null);
	        db.delete(DbTableName.REPAIR,"devicelistid='"+devicelistid+"'",null);
	 
	return false;
	 
     }
     /**
      * 添加绑定信息
      * @param deviceid 
      * @param rfid
      * @param latitude
      * @param longitude
      * @return
      */
     public boolean insertDeviceBanding(String deviceid,String rfid,Double latitude,Double longitude){
	        boolean b=false;
	        
	        ContentValues value=new ContentValues();
	        value.put("RFIDnumber", rfid);
	        value.put("latitude", latitude);
	        value.put("longitude", longitude);
	        value.put("bandingstatus", "0");
	     int k=   db.update(DbTableName.DEVICEINFO, value,"deviceid='"+deviceid+"'",null);
	     if(k>0){
		 b=true;
	     }
	return b;
     }
     
     /**
      * 添加维修数据
      * @param deviceid
      * @param data
      * @return
      */
     public boolean insertDeviceData(String deviceid,String repairmethod,String faulttype,
	     String replacement,String remark,String isrfid){
	 boolean b=false;
	 ContentValues  value=new ContentValues();
	 value.put("repairmethod", repairmethod);
	 value.put("repairstatus", "1");
	 value.put("isupload", "0");
	// value.put("isnorfid", isrfid);
	 value.put("faulttype", faulttype);
	 value.put("replacement", replacement);
	 value.put("remark", remark);
	 value.put("repairdate", DateUtil.getNowDate());
	int k= db.update(DbTableName.REPAIR, value, "deviceid='"+deviceid+"' and repairtype='1'", null);
	if(k>0){
	    b=true;
	    ContentValues values=new ContentValues();
	    values.put("iscopystatus", "1");
	    db.update(DbTableName.DEVICEINFO, values, "deviceid='"+deviceid+"' and operationtype='3'", null);
	}
	return b;
     }
     
     /**
      * 通过ID查询维修信息
      * @param repairid
      * @return
      */
    public RepairVo  queryRepair(String repairid,String deviceid){
	
	String sql="";
	if(repairid!=null){
	    sql="select * from repairSingle where _id='"+repairid+"' and repairtype='1'";
	}
	if(deviceid!=null){
	    sql="select * from repairSingle where deviceid='"+deviceid+"' and repairtype='1'";
	}
	RepairVo  repair=null;
	Cursor cursor=db.rawQuery(sql, null);
	if(cursor.moveToNext()){
	    repair=new RepairVo();
	    repair.setFaultType(cursor.getString(cursor.getColumnIndex("faulttype")));
	    repair.setRemark(cursor.getString(cursor.getColumnIndex("remark")));
	    repair.setRepairDate(cursor.getString(cursor.getColumnIndex("repairdate")));
	    repair.setRepairid(cursor.getString(cursor.getColumnIndex("_id")));
	    repair.setRepairmethod(cursor.getString(cursor.getColumnIndex("repairmethod")));
	    repair.setRepairStatus(cursor.getString(cursor.getColumnIndex("repairstatus")));
	    repair.setReParts(cursor.getString(cursor.getColumnIndex("replacement")));
	    
	}
	if(cursor!=null){
	    cursor.close();
	}
	return repair;
	
	
    }
    
    /**
     *查询所有表册
     * @return
     */
    public List<SpinnerVo>  queryAllDeviceList(){
	List<SpinnerVo> list=new ArrayList<SpinnerVo>();
	SpinnerVo s=new SpinnerVo("0", "请选择");
	list.add(s);
	String sql="select * from devicelist where operationtype= '3'  ";
	Cursor cursor=db.rawQuery(sql, null);
	while(cursor.moveToNext()){
	    String value=cursor.getString(cursor.getColumnIndex("name"));
	  
	    SpinnerVo  spinner=new SpinnerVo(cursor.getString(cursor.getColumnIndex("devicelistid")), value);
	    list.add(spinner);
	}
	if(cursor!=null){
	    cursor.close();
	}
	return list;
    }
    
    /**
     * 更改是否有图片状态
     * @param repairid
     * @param isimage
     */
     public void modifyCopystatus(String repairid,String isimage){
	 ContentValues values=new ContentValues();
	 values.put("isimage", isimage);
	int k= db.update(DbTableName.REPAIR, values, "_id='"+repairid+"'",null);
	if(k>0){
		System.out.println("------有图片--------");
	}else{
	    System.out.println("-------无图片----");
	}

	 
     }
     
     /**
      * 查询所有 下载的图文图片
      * @return
      */
     public List<DownloadItem>  queryNoDown(){
 	FileNameUtil f=new FileNameUtil();
 	String sql="select * from graphicnavigation where type='3' and isimg='1' " +
 			" and isdownload='0' ";

 	Cursor c=db.rawQuery(sql, null);
	
 	List<DownloadItem> list=new ArrayList<DownloadItem>();
 	String webdesc="";
 	String othernumber="";
 	String filename="";
 	String s[]=null;
 	String path="";
 	while(c.moveToNext()){
 	      webdesc=c.getString(c.getColumnIndex("imgwebname"));
 	      othernumber=c.getString(c.getColumnIndex("othernumber"));
 	      s=webdesc.split("/");
 	      filename=s[s.length-1];
 	      path=f.getSDPath()+"/DeviceFile/DaoHang/"+othernumber;
 	      f.SDCardPath("DaoHang");
 	   
 	      File file=new File(path+"/"+filename);
 	      if(!file.exists()){
 		  UpdateVo uv=new UpdateVo();
 		  ContentValues values=new ContentValues();
 		  values.put("isdownload", "1");
 		  values.put("imgpath", path+"/"+filename);
 		  values.put("isimg", "1");
 		  uv.setTablename(DbTableName.NAVIGATION);
 		  uv.setValues(values);
 		  uv.setWhereClause("_id='"+c.getString(c.getColumnIndex("_id"))+"'");
 		
 		  DownloadItem item=new DownloadItem(filename, webdesc, path,uv);
 		  list.add(item);
 	      }else{
 		  ContentValues values=new ContentValues();
 		  values.put("imgpath", path+"/"+filename);
 		  values.put("isimg", "1");
 		  values.put("isdownload", "1");
 		  db.update(DbTableName.NAVIGATION, values, "_id='"+c.getString(c.getColumnIndex("_id"))+"'", null);
 	      }
 	}
 	
 	if(c!=null){
 	    c.close();
 	}
 	return list;
 	
     }
     
     /**
      * 查询所有未上的巡检数据
      * @param imei
      * @return
      */
     public List<UploadItem> queryCopyData(String imei,String copyid){
 	
 	String sql="select * from repairSingle where  repairtype='1'  " +
 			"  and isupload='0' and repairstatus='1' ";
 	Cursor cursor=db.rawQuery(sql, null);
 	String deviceid="";
 	String devicelistid="";
 	String repairid="";
 	Cursor c=null;
 	List<UploadItem> list=new ArrayList<UploadItem>();
 	while(cursor.moveToNext()){
 	    UploadItem item=new UploadItem();
 	    item.setUrl(RequestUrl.UPLOAD_DATA);
 	    Map<String, String> map=new HashMap<String, String>();
 	     deviceid=cursor.getString(cursor.getColumnIndex("deviceid"));
 	     devicelistid=cursor.getString(cursor.getColumnIndex("devicelistid"));
 	     repairid= cursor.getString(cursor.getColumnIndex("_id"));
 	     map.put("valveId", deviceid);//阀门ID
 	     map.put("dataType", "2");//类型
 	     map.put("repairType", "0");
 	     
 	      map.put("dataRepair",fault(cursor.getString(cursor.getColumnIndex("faulttype"))));
 	      map.put("doDate", cursor.getString(cursor.getColumnIndex("repairdate")));
 	      map.put("cpId", copyid);
 	      map.put("mark", cursor.getString(cursor.getColumnIndex("remark")));
 	      map.put("change", cursor.getString(cursor.getColumnIndex("replacement")));
 	     map.put("joblist", devicelistid);
 	    List<UpdateVo> update=new ArrayList<UpdateVo>();	    
 	    UpdateVo upda=new UpdateVo();
 	   upda.setTablename(DbTableName.REPAIR);   
 	   ContentValues value=new ContentValues();
 	   value.put("isupload", "1");
 	   upda.setValues(value);
 	   upda.setWhereClause("_id="+cursor.getInt(cursor.getColumnIndex("_id")));
 	   String s1=cursor.getString(cursor.getColumnIndex("isimage"));
 	  boolean isimage=false;
 	   if(!TextUtils.isEmpty(s1)){
 	       if(s1.equals("1")){
 		   isimage=true;
 	       }
 	   }
 	 
 	   update.add(upda);
 	    item.setUp(update);
 	    item.setMap(map);	
 	    System.out.println("-------是否有图片------"+isimage);
 	   if(isimage){
 	      String sql1="select * from resources where otherid='"+repairid+"' and status='"+3+
 	 		    "' and  type='1'";
 	 		    c=db.rawQuery(sql1, null);
 	 		    List<UploadPOVO> imglist=new ArrayList<UploadPOVO>();
 	 		    while(c.moveToNext()){
 	 			File f=new File(c.getString(c.getColumnIndex("path")));
 	 			System.out.println("---FileName---------"+f.getName());
 	 			if(f.exists()){
 	 			    UploadPOVO up=new UploadPOVO();
 	 			    up.setFilevalue(f);
 	 			    up.setFileVariable("image");
 	 			   
 	 			    imglist.add(up);
 	 			}
 	 		    }
 	 		    if(imglist.size()>0){
 	 			item.setUpfile(imglist);
 	 		    }
 	 	    
 	 	 
 	   }
 	   list.add(item);
 	}
 	System.out.println("------抄表数据长度-------"+list.size());
         if(c!=null){
             c.close();
         }
         if(cursor!=null){
             cursor.close();
         }
 	return list;
 	   
     }
     
     public String fault(String info){
	 String str="";
	 String[] ss=info.split(",");
	 for(int i=0;i<ss.length;i++){
	     if(ss[i].equals("1")){
		 str=str+(i+1);
	     }
	 }
	return str;
     }
}
